package xm.chengdu.com.beijing_211;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.github.czy1121.view.RoundButton;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;
import com.sdwfqin.cbt.Content;
import utils.FaSong;
import utils.SpfUtils;

public class SubareaActivity extends Activity {

    @BindView(R.id.img_back)
    RelativeLayout imgBack;
    @BindView(R.id.textView4)
    TextView textView4;
    @BindView(R.id.fuwuqi)
    TextView fuwuqi;
    @BindView(R.id.editText3)
    EditText editText3;
    @BindView(R.id.textView5)
    TextView textView5;
    @BindView(R.id.Email)
    TextView Email;
    @BindView(R.id.bt_clear)
    RoundButton btClear;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_subarea);
        ButterKnife.bind(this);
        String zhi = (String) SpfUtils.get(SubareaActivity.this, "zhi", "1");
        editText3.setText(zhi);

    }

    @OnClick({R.id.img_back, R.id.bt_clear})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.bt_clear:

                if (!Content.isConn) {
                    Toast.makeText(this, "Please connect to Bluetooth first.", Toast.LENGTH_SHORT).show();
                    return;
                }


                String gecaos = editText3.getText().toString().trim();
                SpfUtils.put(SubareaActivity.this, "zhi", gecaos);

                if (TextUtils.isEmpty(gecaos)) {
                    Toast.makeText(this, "Input can not be empty!", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (gecaos.length() != 2) {
                    Toast.makeText(this, "Please enter two digit number.", Toast.LENGTH_SHORT).show();
                    return;
                }
                gecaos = FaSong.fenquyugecao(gecaos);
                MyEvent eventsgecaos = new MyEvent();
                eventsgecaos.setType("message");
                eventsgecaos.setContent(gecaos);
                EventBus.getDefault().post(eventsgecaos);
                Toast.makeText(this, "success!", Toast.LENGTH_SHORT).show();
                finish();
                break;
        }
    }
}
